package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.aid.AidReceipt;
import com.ruoyi.system.service.aid.IAidReceiptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资接收Controller
 */
@RestController
@RequestMapping("/system/aid/receipt")
public class AidReceiptController extends BaseController {
    @Autowired
    private IAidReceiptService aidReceiptService;

    /**
     * 查询物资接收列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AidReceipt aidReceipt) {
        startPage();
        List<AidReceipt> list = aidReceiptService.selectAidReceiptList(aidReceipt);
        return getDataTable(list);
    }

    /**
     * 导出物资接收列表
     */
    @Log(title = "物资接收", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AidReceipt aidReceipt) {
        List<AidReceipt> list = aidReceiptService.selectAidReceiptList(aidReceipt);
        ExcelUtil<AidReceipt> util = new ExcelUtil<AidReceipt>(AidReceipt.class);
        util.exportExcel(response, list, "物资接收数据");
    }

    /**
     * 获取物资接收详细信息
     */
    @GetMapping(value = "/{receiptId}")
    public AjaxResult getInfo(@PathVariable("receiptId") Long receiptId) {
        return success(aidReceiptService.selectAidReceiptById(receiptId));
    }

    /**
     * 新增物资接收
     */
    @Log(title = "物资接收", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AidReceipt aidReceipt) {
        return toAjax(aidReceiptService.insertAidReceipt(aidReceipt));
    }

    /**
     * 修改物资接收
     */
    @Log(title = "物资接收", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AidReceipt aidReceipt) {
        return toAjax(aidReceiptService.updateAidReceipt(aidReceipt));
    }

    /**
     * 删除物资接收
     */
    @Log(title = "物资接收", businessType = BusinessType.DELETE)
    @DeleteMapping("/{receiptIds}")
    public AjaxResult remove(@PathVariable Long[] receiptIds) {
        return toAjax(aidReceiptService.deleteAidReceiptByIds(receiptIds));
    }

    /**
     * 根据状态查询接收记录
     */
    @GetMapping("/status/{status}")
    public AjaxResult getByStatus(@PathVariable("status") String status) {
        return success(aidReceiptService.selectAidReceiptByStatus(status));
    }
}